﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_role_master
{
    public DAL_tbl_role_master()
    {

    }



    public List<tbl_role_master> select(int ROLE_ID)
    {
        List<tbl_role_master> list = new List<tbl_role_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ROLE_ID,ROLE_NAME,IS_ACTIVE,CREATED_BY,CREATED_DATE from tbl_role_master where ROLE_ID=@ROLE_ID";
        cmd.Parameters.AddWithValue("@ROLE_ID", ROLE_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_role_master()
            {
                ROLE_ID = Convert.ToInt32(dr["ROLE_ID"]),
                ROLE_NAME = dr["ROLE_NAME"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_role_master> selectAll()
    {
        List<tbl_role_master> list = new List<tbl_role_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ROLE_ID,ROLE_NAME,IS_ACTIVE,CREATED_BY,CREATED_DATE from tbl_role_master Order By ROLE_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_role_master()
            {
                ROLE_ID = Convert.ToInt32(dr["ROLE_ID"]),
                ROLE_NAME = dr["ROLE_NAME"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String ROLE_NAME, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_role_master(ROLE_NAME, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@ROLE_NAME, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ROLE_NAME", ROLE_NAME);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ROLE_ID, String ROLE_NAME, bool IS_ACTIVE)
    {
        int i = 0;
        string sql = @"Update tbl_role_master SET ROLE_NAME=@ROLE_NAME, IS_ACTIVE=@IS_ACTIVE WHERE ROLE_ID=@ROLE_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ROLE_ID", ROLE_ID);
        cmd.Parameters.AddWithValue("@ROLE_NAME", ROLE_NAME);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ROLE_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_role_master WHERE ROLE_ID=@ROLE_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ROLE_ID", ROLE_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}